package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.controller.BaseController;
import com.example.domain.Friend;
import com.example.result.JsonResult;
import com.example.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/friend")
public class FriendController extends BaseController {
    @Autowired
    private FriendService friendService;

    @GetMapping("/getFriends")
    public JsonResult getFriends(HttpSession session){
        Long sessionUId = getSessionUId(session);
        System.out.println(sessionUId);
        QueryWrapper<Friend> wrapper=new QueryWrapper<>();
        wrapper.eq("uid",sessionUId);
        wrapper.eq("is_delete",0);
        List<Friend> list = friendService.list(wrapper);
        if(list==null){
            throw new RuntimeException("获取信息失败");
        }
        return new JsonResult(true,"",list);
    }
}
